using System;
using Evaluant.Uss;
using Evaluant.Uss.ObjectContext;
using System.Collections;

namespace PersistenceManagerWeaver
{
	public class Mixin : IPersistable
	{
		public void Initialize()
		{
			this._entity = new Entity(ObjectContext.ConvertNamespaceDomainToEuss(this.GetType().FullName));
		}

		public Mixin(Entity entity)
		{
			_entity = entity;
		}

		#region Membres de IPersistable

		void IPersistable.TrackChildren()
		{
			if(_persistenceManager == null)
				return;
		}

//		private Entity _entity;
		protected Entity _entity;

		Evaluant.Uss.Entity IPersistable.Entity
		{
			get { return _entity; }
			set { _entity = value; }
		}

//		private bool isLoaded;

		[NonSerialized]

		protected ObjectContext _persistenceManager;

		ObjectContext IPersistable.ObjectContext
		{
			get { return _persistenceManager; }
			set { _persistenceManager = value; }
		}

		~Mixin()
		{
			if(_persistenceManager != null)
				_persistenceManager.RemoveFromCache(this);
		}

//		// Patron de tissage de field en get
//		private void BeforeGetAttribute(Type type, string fieldName)
//		{
//			if(_entity.FindEntry(fieldName) != null) 
//				field = (type)_entity.GetValue(fieldName);
//		}
		
//
//		private void AfterSetAttribute()
//		{
//			_entity["myFieldName"] = myField;
//		}


		#endregion
	}
}
